package com.education.springbootdemo.controller;

import com.education.springbootdemo.domain.Resp;
import com.education.springbootdemo.domain.doto.Category;
import com.education.springbootdemo.exception.BizException;
import com.education.springbootdemo.service.CategoryService;
import com.education.springbootdemo.utils.SessionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    //今天的主题

    //创建分类
    @RequestMapping("add")
    public Resp<Category> add(@RequestBody Category category) throws BizException {
        category.setCreateUser(4L);
        category.setCreateTime(LocalDateTime.now());
        category.setUpdateTime(LocalDateTime.now());
        Category cat = categoryService.add(category);
        return Resp.success(cat);
    }

    //删除分类

    //查询分类列表

    @RequestMapping("list")
    public Resp<List<Category>> list() throws BizException {
        return Resp.success(categoryService.list());
    }
}
